package AtmSystem;

import java.util.*;

public class ClientDB
{
	private Vector<Client> clients;

	public ClientDB ()
		{
		clients=new Vector();
		}

	public boolean add(Client newClient)
		{
			return clients.add(newClient);
		}

	public boolean remove(String newUsername)
		{
		Client removedClient = isExsit(newUsername);
		if(removedClient != null)
			{
			clients.remove(removedClient);
			return true;
		}
		
		else return false;
		}

	public Client isExsit(String newUsername,String newPassword)
		{  
		for (int index=0;index<clients.size();index++ )
			{
				if  (clients.get(index).getUsername().equals(newUsername)
				&&clients.get(index).getPassword().equals(newPassword))
				{
				return (Client) ( clients.get(index) );
				}	
			}
		return null;
		}

		public Client isExsit(String newUsername)
		{
			for(int index = 0;index<getNumbers();index ++)
			{
				if (clients.get(index).getUsername().equals(newUsername))
				{
					return (Client) ( clients.get(index) );
				}
			}
			return null;
		}

		
		public Client isExsit(int CardNumber)
		{
			for(int index = 0;index<getNumbers();index ++)
			{
				for(int i =0;i<get(index).getBankAccountDB().getNumbers();i++)
				{
					if (get(index).getBankAccountDB().get(i).getCardNumber()==CardNumber)
				return (Client) (get(index) );
				}
			}
			return null;
		}

	public int getNumbers()
		{
		return clients.size();
		}

		public Client get(int index)
		{
			return (Client) clients.get(index);
		}
}
